<template>
	<div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="关键字">
							<a-input autocomplete="off" class="field-right" placeholder="请输入编号/标题搜索"
								v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<!-- 课程 -->
					<a-col :span="8">
						<a-form-item label="课程类型">
							<a-select :allowClear="true" v-decorator="['ActivityTypeID']" placeholder="全部"
								optionFilterProp="children" showSearch @change="selectChange">
								<a-select-option v-for="(item, index) in ActivityTypeData" :key="item.ID"
									:value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<!-- <a-col :span="8">
						<a-form-item label="课程分值">
							<a-select :allowClear="true" v-decorator="['ActivityTypeScoreID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in ActivityTypeScoreList" :key="item.ID"
									:value="item.ID">
									参与分:{{ item.JoinScore }}工作人员分:{{ item.WorkerScore }}观众分:{{ item.AudienceScore }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col> -->
					<!-- <a-col :span="8">
						<a-form-item label="课程奖项" prop="ActivityTypePrizeID">
							<a-select :allowClear="true" v-decorator="['ActivityTypePrizeID']" style="width:100%">
								<a-select-option v-for="(item, index) in ActivityTypePrizeTypeList" :key="item.Key"
									:value="item.ID">{{ item.Title }}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col> -->
					<!-- 课程end -->
					<a-col :span="8">
						<a-form-item label="部门">
							<a-select :allowClear="true" v-decorator="['departCode']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in DepartCodeList" :key="index"
									:value="item.Code">{{ item.Name }}</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<!-- <ClubSearch :span="8" label="学生组织" name="clubID" ref="clubID" @tap="searchValueFun"></ClubSearch> -->
					<ClubSearch :span="8" label="班级" name="classID" ref="classID" @tap="searchValueFun"></ClubSearch>
					<ClubSearch :span="8" label="申请人" name="applyUserNo" ref="applyUserNo" @tap="searchValueFun">
					</ClubSearch>
					<a-col :span="8">
						<a-form-item label="申请时间">
							<a-range-picker v-decorator="[`data`]" />
						</a-form-item>
					</a-col>
					<a-col :span="12" style="margin-top:4px;">
						<a-button-group>
							<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
							<a-button @click="handleReset" class="btn2">重置</a-button>
							<a-button type="primary" class="btn" @click="allApplyHander">批量审核</a-button>
							<a-button type="danger" class="btn"  @click="deleteAllList">批量删除</a-button>
							<!-- <a-button type="primary" v-if="checkall" style="margin-left: 8px;" class="btn" @click="allcheck">一键审批</a-button> -->
						</a-button-group>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div style="margin-top:20px;">
			<el-table :data="data" v-loading="loading" border @selection-change="handleSelectionChange"
				:max-height="tableHeight" highlight-current-row style="width: 100%;">
				<el-table-column type="selection" width="55" fixed="left"></el-table-column>
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="No" label="编号" width="130" fixed="left">
					<template slot-scope="scope">
						{{ scope.row.CreditApplyNo || '暂无' }}
					</template>
				</el-table-column>
				<el-table-column prop="ActivityTitle" label="标题" min-width="130" fixed="left">
					<template slot-scope="scope">
						{{ scope.row.CreditApplyTitle  }}
					</template>
				</el-table-column>
				<el-table-column prop="AddUserNo" label="申请人" min-width="160">
					<template slot-scope="scope">
						<a-tag color="blue">{{ scope.row.AddUserNo }}/{{ scope.row.AddUserName }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="AddTime" label="申请时间" min-width="200"></el-table-column>
				<!-- <el-table-column prop="CreditApplyType" label="申请类型" min-width="100" show-overflow-tooltip=""></el-table-column> -->
				<el-table-column prop="ChargeUserNo" label="审批节点" min-width="160">
					<template slot-scope="scope">
						<a-tag color="blue">{{ scope.row.FlowTypeName }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="98" fixed="right">
					<template slot-scope="scope">
						<!-- <oprateBtn title="修改" icon="icon-editor1" v-if="IsAgreeUpdate"  color="green"
							@tap="changeRow(scope.row)"></oprateBtn> -->
						<!-- <a-tooltip placement="top">
							<template slot="title">
								详情
							</template>
							<i class="iconfont icon-xiangqing" style="color: #1890FF;"
								@click="seeList(scope.row, 'CreditApplyDetail')"></i>
						</a-tooltip> -->
						<!-- <a-tooltip placement="top">
							<template slot="title">附件</template>
							<i title="附件" class="iconfont icon-fujian" style="color: #1890FF;"
								@click="seeList(scope.row, 'CreditFlowEn')"></i>
						</a-tooltip> -->
						<a-tooltip placement="top">
							<template slot="title">
								<span>审批</span>
							</template>
							<i class="iconfont icon-shenpi" style="color: red;" @click="seeList(scope.row, 'CreditApplyDetail')"></i>
						</a-tooltip>
						<i title="删除" v-if="IsAgreeDelete" class="iconfont icon-delete1" style="color: red;" @click="deletemember(scope.row)"></i>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
				
		</div>
	</div>
</template>

<script>
	import moment from 'moment';
	import Func from '@/utils/func';
	import ClubSearch from '@/components/SearchForm/ClubSearch.vue'
	
	import {
		ManageCreditFlowDoGetExamPageList,
		GetActivityStateList,
		GetClubPageListCommon,
		GetUserList,
		GetClassList,
		GetActivityTypeList,
		CommonDoGetActivityTypeScoreList,
		CommonDoGetActivityTypePrizeList,
		ManageUserScoreDoGetManageDepartList,
		ManageCreditFlowDoDelete
	} from '@/api/follow';
	const data = [];
	export default {
		props: {
			flowTypeID: String,
			// IsAgreeUpdate: Boolean,
			DepartCodeList:Array,
			ActivityTypeData:Array
		},
		watch: {
			flowTypeID: function(flowTypeID) {
				console.log(this.nowflowTypeID);
				this.nowflowTypeID = flowTypeID;
				this.getList();
			}
		},
		components: {
			ClubSearch
		},
		data() {
			return {
				checkall:false,
				IsAgreeUpdate:false,
				IsAgreeDelete:false,
				// ActivityTypeData: [],
				ActivityTypeScoreList: [],
				ActivityTypePrizeTypeList: [],
				// DepartCodeList: [],
				applyIf: false,
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				ActivityStateList: [],
				ClubList: [],
				tabkey: 1,
				userList: [],
				fetching: false,
				nowflowTypeID: '',
				multipleSelection: [],
				ClassList: []
			};
		},
		computed: {},
		created() {
			// this.getList();

		},
		mounted() {
			// this.getOtherList();
		},
		methods: {
			
			async getScore(key) {
				let data = {};
				data.activityTypeID = key
				let res4 = await CommonDoGetActivityTypeScoreList(data);
				this.ActivityTypeScoreList = res4.data.data;
			},
			async getJiang(key) {
				let data = {};
				data.activityTypeID = key
				let res = await CommonDoGetActivityTypePrizeList(data);
				this.ActivityTypePrizeTypeList = res.data.data
			},
			selectChange(e) {
				this.getScore(e);
				this.getJiang(e);
			},
			moment,
			searchValueFun(name, value) {
				this.values = {
					...this.values,
					[name]: value
				}
				console.log(this.values)
			},
			async fetchClass(value) {
				this.fetching = true;
				let myReg = /^[^a-zA-Z]+$/;
				if (value && value.length > 1) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetClassList(data);
					this.fetching = false;
					this.ClassList = res.data.data;
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			tabChange(key) {
				this.tabkey = key;
			},
			filterOption(input, option) {
				return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
			},
			async fetchUser(value) {
				this.fetching = true;
				let myReg = /^[^a-zA-Z]+$/;
				if (value && value.length > 1) {
					let data = {};
					data.key = value;
					data.top = 20;
					let res = await GetUserList(data);
					this.fetching = false;
					this.userList = res.data.data;
				}
			},
			async fetchClub(value) {
				let myReg = /^[^a-zA-Z]+$/;
				if (value && value.length > 1) {
					let data = {};
					data.key = value;
					let res = await GetClubPageListCommon(data);
					this.ClubList = res.data.data;
				}
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					if (values.data && values.data.length > 0) {
						values.startTime = values.data[0].format('YYYY-MM-DD');
						values.endTime = values.data[1].format('YYYY-MM-DD');
					}
					this.values = {
						...this.values,
						...values
					};
					this.checkall=true
					this.getList();
				});
			},
			allcheck(){
				let value2=this.values;
				value2.flowTypeID=this.nowflowTypeID;
				this.$emit('allcheck', value2);
			},
			handleReset() {
				this.form.resetFields();
				// this.$refs.clubID.value = undefined
				this.$refs.classID.value = undefined
				this.$refs.applyUserNo.value = undefined
				this.values = {};
				this.checkall=false;
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				console.log(333);
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				data.flowTypeID = this.nowflowTypeID;
				let res = await ManageCreditFlowDoGetExamPageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
				this.IsAgreeDelete=res.data.pageInfo.IsAgreeDelete;
				this.IsAgreeUpdate=res.data.pageInfo.IsAgreeUpdate;
			},
			async getOtherList() {
				// let res = await GetActivityStateList();
				// this.ActivityStateList = res.data.data;
				let res = await ManageUserScoreDoGetManageDepartList();
				this.DepartCodeList = res.data.data;
				let res3 = await GetActivityTypeList()
				this.ActivityTypeData = res3.data.data
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},

			seeList(text, name) {
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						ActivityID: text.ActivityID,
						followId: text.ID,
						type: 1,
						source:'申请审批列表',
						IsAgreeUpdate:this.IsAgreeUpdate?1:0,
						text:JSON.stringify(text)
					}
				});
			},
			allApplyHander() {
				if (this.multipleSelection.length == 0) {
					this.$message.error('请选择要处理的数据！')
					return false
				}
				this.applyHander(this.multipleSelection)
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该申请吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await ManageCreditFlowDoDelete(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			deleteAllList() {
				let that=this;
				if (this.multipleSelection.length == 0) {
					this.$message.error('请先选择要删除的数据！');
				} else {
					let that = this;
					this.$confirm({
						title: '提示',
						content: '确定要删除选中的数据吗？',
						okText: '确认',
						cancelText: '取消',
						async onOk() {
							let list = that.multipleSelection;
							console.log(list);
							for (let i = 0, len = list.length; i < len; i++) {
								let data = {};
								data.id = list[i].ID;
								let res = await ManageCreditFlowDoDelete(data);
							}
							that.getList();
						}
					});
				}
			},
			applyHander(item) {
				this.$emit('applyHander', item);
				// this.text = item
				// this.applyIf = true
			},
			changeRow(item){
				this.$emit('changeRow', item);
			},
			closeFun() {
				this.getList();
			}
		}
	};
</script>

<style lang="less" scoped>
	.home-form /deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;
	}

	.home-form /deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	.home-form /deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	.option {
		margin-top: 10px;
		margin-bottom: 20px;
		overflow: hidden;
	}

	.option .btn {
		height: 36px;
		line-height: 36px;
		padding: 0 10px;
		float: left;
		background: #1890ff;
		color: #fff;
		margin-right: 10px;
		border-radius: 3px;
		cursor: pointer;
		border: none;
	}

	.foot {
		text-align: center;
		margin-top: 100px;
	}

	.el-pagination {
		margin-top: 10px;
	}
</style>
